﻿using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;

namespace Sample.Novel.Domain.Books.Entites
{
    public class Book
        : Entity<Guid>, IHasCreationTime
    {
        public string Name { get; set; }
        
        public string Description { get;set; }

        public Guid AuthorId { get;set;}

        public string AuthorName { get; set; }

        public Guid CategoryId { get;set;}

        public string CategoryName { get; set; }

        public virtual List<Volume> Volumes { get; protected set; }
        public DateTime CreationTime{get; set;}

        protected Book() { }

        public Book(
            Guid id,
            [NotNull] string name,
            [NotNull] string description,
            Guid authorId,
            [NotNull] string authorName,
            Guid categoryId,
            [NotNull] string categoryName
            ) 
        { 
          
            this.Id = id;
            this.Name = name;
            this.Description = description;
            this.AuthorId = authorId;
            this.AuthorName = authorName;
            this.CategoryId = categoryId;
            this.CategoryName = categoryName;
            this.Volumes = new List<Volume>();
        }

        //添加分卷
        public void AddVolume(Volume volume) {
            if (Volumes.Any(v => v.Title == volume.Title)) {
                return;
            }

            Volumes.Add(volume);
        }
    }
}
